package com.woniuxy.exam.service.impl;

import com.woniuxy.commons.entity.PaperStructure;
import com.woniuxy.exam.mapper.PaperStructureMapper;
import com.woniuxy.exam.service.PaperStructureService;
import com.woniuxy.exam.utils.PaperUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 余枭春
 * @Date 2020/7/20 9:49
 * @Description:
 **/
@Service
public class PaperStructureServiceImpl implements PaperStructureService {

    //默认的试卷结构
    private PaperStructure paperStructure_default=new PaperStructure()
            .setAnswerNum(2).setAnswerScore(20)
            .setCompletionNum(2).setCompletionScore(20)
            .setMultipleChoiceNum(2).setMultipleChoiceScore(20)
            .setSingleChoiceNum(2).setSingleChoiceScore(20)
            .setTrueOrFalseNum(2).setTrueOrFalseScore(20)
            .setQuestionTotalNum(10).setQuestionTotalScore(100);
    @Autowired
    private PaperStructureMapper paperStructureMapper;
    @Override
    public PaperStructure findPaperStructureByPaperId(int paperId) {
        return paperStructureMapper.findPaperStructureByPaperId(paperId);
    }

    @Override
    public int insertPaperStructure(PaperStructure paperStructure) {
        PaperStructure paperStructure1= paperStructureMapper.findPaperStructureByPaperId(paperStructure.getPaperId());
        System.out.println(paperStructure1==null);
        if(paperStructure1==null){
            //自动组卷，将所有值设定改为默认值
            paperStructure_default.setPaperId(paperStructure.getPaperId());
            return paperStructureMapper.insertPaperStructure(paperStructure_default);
        }
        return paperStructureMapper.insertPaperStructure(paperStructure);
    }
}
